package Easy;

// 27.移除元素
public class Solution27 {
    public static int removeElement(int[] nums, int val) {
        int i, k;
        int count = 1, n = 0;
        int length = nums.length;
        if (length == 0)
            return 0;
        if (length == 1) {
            if (nums[0] == val)
                return 0;
            else
                return 1;
        }
        for (i = 0, k = 0; k < length; i++, k++) {
            if (nums[i] == val) {
                nums[i] = nums[nums.length - count];
                i--;
                count++;
            } else {
                n++;
            }
        }
        return n;
    }

    public static void main(String[] args) {
        int nums[] = {2};
        System.out.println(removeElement(nums, 1));
    }
}

